﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Common.DLR
{
    /// <summary>
    /// 
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class ListArrayConverter<T>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public T[] ToArray(List<T> list)
        {
            if (list != null && list.Count > 0)
            {
                T[] array = new T[list.Count];
                for(int i=0;i<list.Count;i++)
                {
                    array[i] = list[i];
                }
                return array;
            }
            else
                return null;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public List<T> ToList(T[] array)
        {
            List<T> list=new List<T>();
            if(array !=null && array.Length>0)
            {
                foreach(T element in array)
                {
                    list.Add(element);
                }
            }
            return list;
        }
    }
}
